#include "widget.h"
#include "ui_widget.h"

#include <QPainter>
#include <QImage>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

void Widget::paintEvent(QPaintEvent *event)
{
    // 作为画布的功能
//    QImage img(300, 300, QImage::Format_RGB32);
//    img.fill(Qt::blue);

//    QPainter painter(&img);

//    painter.drawPie(10, 10, 100, 60, 10, 50);

//    img.save("e:/2.jpg");


    // 像素级绘制
    QImage img("D:/lenovo/Pictures/Saved Pictures/壁纸头像/1photo.jpg");

    QPainter painter(this);
    for (int x = 20; x < 70; x++)
    {
        for (int y = 20; y < 70; y++) {
            QRgb c = qRgb(255, 0, 0);
            img.setPixel(x, y, c);
        }
    }

    painter.drawImage(QRect(10, 10, 500, 500), img);

}

Widget::~Widget()
{
    delete ui;
}
